Java: Tools by Andrew Binstock & Pankaj Kumar

Java: Tools by Andrew Binstock & Pankaj Kumar

Author:Andrew Binstock & Pankaj Kumar [Binstock, Andrew]
Language: eng
Format: azw3
Publisher: UNKNOWN
Published: 2018-11-24T16:00:00+00:00


New Block

Transaction statusTransaction 1

Future <...>

web3j API Transaction To address Value

Core

Transaction Receipt Transaction Manager Transaction 2 Poll (our transaction)

Transaction 3

Mines

Transaction n

Figure 3. Transaction on Ethereum via web3j

41 4. This transaction is combined with other new transactions to form a block by miners on the Ethereum network. Once a valid block is formed, the block and details of its associ- ated transactions are immortalized on the blockchain.

You can head back over to Etherscan to view the details of your transaction (Figure 4).

Figure 5 show the contents of the block on the blockchain in which the transaction resides.

Figure 4. A receipt of the transaction

Gas I touched earlier in the article on Ether, which is used to pay for the execution of code in the EVM. There are two parameters that need to be speciied with respect to the cost you are prepared to pay for transactions: the gas price and the gas limit. The gas price is the price in Ether you are prepared to pay per gas unit. Each EVM opcode contains a gas cost associated with it. The gas limit is the total amount of gas usage you are willing to pay for the transaction execution. This ensures that all transactions have a inite cost of execution. Details about the gas associated with a transaction are visible in the transaction receipt and Etherscan.

Hello (Ethereum) World Now that I’ve demonstrated a simple transaction, things will start to get interesting as I create the irst smart contract. Ethereum smart contracts are usually written in a language named Solidity, which is a statically typed high-level language. Describing how to use Solidity could ill many articles, so I’m going to keep the example simple. You can read more about Solidity online.

Now let’s use the Greeter contract example. The Greeter contract is the “hello world” example of a smart contract of Ethereum. When you deploy the contract, you pass a UTF 8-encoded string to its constructor. Then, whenever you call the deployed contract, the value of this string is returned by the node on the Ethereum network that processes your request.

contract mortal {

/* Define variable owner of the type address*/ address owner;

/* this function is executed at initialization

and sets the owner of the contract */

function mortal() { owner = msg.sender; } 42 /* Function to recover the funds on the contract */

function kill() {

if (msg.sender == owner) suicide(owner); }

}

contract greeter is mortal {

/* define variable greeting of the type string */ string greeting;

/* this runs when the contract is executed */ function greeter(string _greeting) public { greeting = _greeting;

}

Although the language is unfamiliar, the example above is fairly intuitive to follow. Themortal contract is the base class, and thegreetercontract is a child class.

The creator of the contract is the instance variable owner, of typeaddress;msg.sender is the sender of any transactions with the contract; and the instance variablegreeting is another instance variable.

There are two methods to be concerned with: ■ greeter(string _greeting)is the constructor.

■ greet() is a getter method returning the value ofgreeter. There are two options



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.